﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Admin
{
    public partial class MessageD :BaseCtrl
    {
        private string Act = YuRequest.GetQueryString("Act");
        private int bID = YuRequest.GetQueryInt("bID");
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.OnStart();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected void OnStart()
        {
            if (Act.ToLower() == "edit")
            {
                this.InitUpdate(bID);
            }
            else if(Act.ToLower()=="del")
            {
                this.Del(bID);
            }

        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="bID"></param>
        protected void Del(int bID)
        {
            int rInt = 0;
            rInt= bllBook.Delete(bID);
            if (rInt != 0)
            {
                JScript.AlertAndRedirect("删除成功", "Message.aspx");
            }
            else
            {
                JScript.AlertAndRedirect("系统出错，请联系管理员", "Message.aspx");
            }
        }

         /// <summary>
        ///  填充修改数据
        /// </summary>
        /// <param name="PostID"></param>
        protected void InitUpdate(int bID)
        {
            Yu.Cms.Model.Book mBook = bllBook.GetModel(bID);
            txtName.Text = mBook.bName;
            //txtQQ.Text = mBook.bQq.ToString();
            txtWeb.Text = mBook.bWeb;
            txtEmail.Text = mBook.bEmail;
            lblIp.Text = mBook.PubIp;
            hlIp.NavigateUrl = "http://www.ip138.com/ips.asp?ip=" + mBook.PubIp;
            hlIp.Target = "_blank";
            if (mBook.isPub)
            {
                chkIsPub.Checked = true;
            }
            else
            {
                chkIsPub.Checked = false;
            }
            txtContent.Value = mBook.bContent;
            txtRe.Value = mBook.bReContent;

        }

        /// <summary>
        /// 回复留言
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int rInt = 0;
                Yu.Cms.Model.Book mBook = bllBook.GetModel(bID);
                mBook.bName = txtName.Text.Trim();
                mBook.bWeb = txtWeb.Text.Trim();
                //mBook.bQq = Utils.StrToInt(txtQQ.Text.Trim(), 0);
                mBook.bEmail = txtEmail.Text.Trim();
                mBook.bContent = txtContent.Value;
                mBook.bReContent = txtRe.Value;
                mBook.RePubTitme = DateTime.Now;
                mBook.isPub = chkIsPub.Checked;
                rInt= bllBook.Update(mBook);
                if (rInt != 0)
                {
                    JScript.AlertAndRedirect("编辑成功", "Message.aspx");
                }
                else
                {
                    JScript.AlertAndRedirect("系统出错，请联系管理员", "Message.aspx");
                }
            }
        }
    }
}